package com.str.graphs;

import com.str.PQ.HeapPriorityQueue;
import com.str.PQ.PriorityQueue;

public class KruskalTest {

  private static final int NUM = 6; // Number of vertices
  private static final boolean UNDIRECTED = true;
  
  // Create a graph from array
  public static Graph createGraph(int[][] examp) {
    Graph g = new MatrixGraph(NUM);
   // Graph g = new ListGraph(NUM);

    for (int i=0; i<examp.length; i++) {
      int v1 = examp[i][0];
      int v2 = examp[i][1];
      int dist = 1;  // No weight given -- set at 1       
      if (examp[i].length > 2)
        dist = examp[i][2];
      g.setEdge(v1, v2, dist);
      if (UNDIRECTED) // Also put in edge in other direction
        g.setEdge(v2, v1, dist);
    }
    return g;
  }

  public static void print(Graph g) {
    System.out.println("Number of vertices is " + g.n());
    System.out.println("Number of edges is " + g.e());

    System.out.println("Matrix is:");
    for (int i=0; i<g.n(); i++) {
      for (int j=0; j<g.n(); j++)
        System.out.print(g.weight(i, j) + "  ");
      System.out.println();
    }
    System.out.println();
  }

  // Generic main function for graph tests --
  //   both adjacency list and adjacency graph
  public static void main(String args[]) {
  	
    int[][] examp = {{0, 1, 7},
                     {0, 4, 9},
                     {1, 2, 1},
                     {1, 3, 5},
                     {1, 5, 2},
                     {2, 5, 2},
                     {3, 5, 6},
                     {4, 5, 1}};  	
    Graph g = createGraph(examp);
    print(g);
    PriorityQueue h = new HeapPriorityQueue(); // Heapify the edges
    Kruskal.kruskal(g, h);
  }
}
